#pragma once
#include "Protocol.hpp"
#include <iostream>
// 计算器的具体执行逻辑
class Cal {
public:
    Response Execute(Requset& req) {
        Response resp(-1, 0); 
        switch (req.Oper()) {
            case '+':
                resp.SetResult(req.X() + req.Y());
                break;
            case '-':
                resp.SetResult(req.X() - req.Y());
                break;
            case '*':
                resp.SetResult(req.X() * req.Y());
                break;
            case '/':
                {
                    if(req.Y() == 0) {
                        resp.SetCode(1); // 表示除零异常
                    }else {
                        resp.SetResult(req.X() / req.Y());
                    }
                }
                break;
            case '%':
                {
                    if(req.Y() == 0) {
                        resp.SetCode(1); // 表示除零异常
                    }else {
                        resp.SetResult(req.X() % req.Y());
                    }
                }
                break;
            default:
                resp.SetCode(3); // 非法操作
                break;
        }
        return resp;
    }
};